﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class SertificateEducation
    {
        public void ImportList(List<Classes.SertificateEducation> SertificateEducationList)
        {
            var mdb = new MedregDBDataContext();

            var sSpec = new Classes.SertificateSpeciality();
            var Spec = new SertificateSpeciality();
            Spec.ImportList(sSpec.getSertificateSpecialityList(SertificateEducationList));

            var sEdIst = new Classes.EducationInstitution();
            var EdInst = new EducationInstitution();
            EdInst.ImportList(sEdIst.getEducationInstitutionList(SertificateEducationList));



            foreach (Classes.SertificateEducation sertificateEducation in SertificateEducationList)
            {
                var sertificateEducation1 = new SertificateEducation
                {
                    IssueOrg = sertificateEducation.IssueOrg.ID,
                    IssueDate = sertificateEducation.IssueDate,
                    SertificateSerie = sertificateEducation.SertificateSerie,
                    SertificateNumber = sertificateEducation.SertificateNumber,
                    EducationSpeciality = sertificateEducation.EducationSpeciality.ID,
                    Employee = sertificateEducation.Employee.ID
                };

                IEnumerable<SertificateEducation> query = (from cr in mdb.SertificateEducation
                                                       where cr.Employee == sertificateEducation.Employee.ID
                                                       select cr
                                                   ).ToList();
                mdb.SertificateEducation.DeleteAllOnSubmit(query);
                mdb.SertificateEducation.InsertOnSubmit(sertificateEducation1);
            }
            mdb.SubmitChanges();
        }
    }
}
